/**
 * Copyright (c) 2019, NewStrength. All rights reserved.
 * 2019-01-28 10:22:41
 */
package cn.newstrength.shihaipeng.service;

import cn.newstrength.shihaipeng.data.SHPSampleObj;
import cn.newstrength.wtdf.web.mybatis.service.MapperService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.newstrength.zhangtairan.data.ZTRSampleObj;
//import cn.newstrength.wtdf.plugin.mybatis.service.MapperService;
import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.FailureTranResult;
import cn.newstrength.wtdf.plugin.result.TranResult;

/**
 * 带有数据库事务的，需要使用Service调用
 * <p>Service类中传入参数统一使用 TranParams<P>，返回值统一使用 TranResult<R></p>
 * <p>Step只负责数据的准配，并不做任何业务逻辑的判断及处理，Service 中实现业务的逻辑判断及结果处理</p>
 * @author Xd
 *
 */
@Service
public class SHPSampleService {
	
	private static final Logger logger = LoggerFactory.getLogger(SHPSampleService.class);
	
	@Autowired
	private MapperService mapperService;
	
	@Transactional
	public TranResult<SHPSampleObj> insert(TranParams<SHPSampleObj> params){
		/*
		 * 获取实体类
		 * 
		 */
		SHPSampleObj sampleObj = params.getParam();
		if(sampleObj==null){
			return new FailureTranResult<>(-1, "参数不能为空!");
		}
		/*
		 * 调用数据库操作服务
		 */
		TranResult<SHPSampleObj> tranResult = mapperService.insert(params);
		logger.info("执行结果：{}",tranResult.toString());
		/*
		 * 返回
		 */
		return tranResult;
	}
}
